// This File is part of the "nyaqt" Project
// 
// Copyright  2009 sometmes@gmail.com
// All rights reserved
// 
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.



using System;
using System.Data;
using System.Collections.Generic;

namespace nyaqt.Plugins
{
    public delegate void ConnectionMessageDelegate(string text);
    public interface IConnectionProperties
    {
        IConnectionInfo ConnectionInfo { get; set; }
        IDbConnection Connection { get; set; }
        string Database { get; }
        string Server { get; }
        string UserName { get; }
        string ServerBrowseKey { get; }
        //string ConnectionStringPasswordKey { get; }
        List<DatabaseEntityInfo> GetDatabases();
        List<DatabaseEntityInfo> GetDatabaseTables(string database);
        List<DatabaseEntityInfo> GetDatabaseSystemTables(string database);
        List<DatabaseEntityInfo> GetDatabaseViews(string database);
        List<DatabaseEntityInfo> GetDatabaseStoredProcedures(string database);
        List<DatabaseEntityInfo> GetDatabaseTableColumns(string database, string tableNamespace, string table);
        List<DatabaseEntityInfo> GetDatabaseTableRelations(string database, string tableNamespace, string table);
        List<DatabaseEntityInfo> GetDatabaseTableRelationColumns(string database, string tableNamespace, string table, string relatedTableNamespace, string relatedTable);
        List<DatabaseEntityInfo> GetDatabaseStoredProcedureParameters(string database, string tableNamespace, string table);
        List<ServerInfo> GetServerList();
        bool ServerAddressEqual(string addr1, string addr2);
        string FormatSelectTopQuery(int top, DatabaseEntityInfo table, List<DatabaseEntityInfo> columns);
        string FormatInsertScript(Dictionary<string, object> row, List<DatabaseEntityInfo> tables, List<DatabaseEntityInfo> columns);
        string FormatUpdateScript(Dictionary<string, object> rowOriginal, Dictionary<string, object> rowCurrent, List<string> cellsSelected, List<DatabaseEntityInfo> tables, List<DatabaseEntityInfo> columns);
        string FormatDeleteScript(Dictionary<string, object> rowOriginal, List<DatabaseEntityInfo> tables, List<DatabaseEntityInfo> columns);
        event ConnectionMessageDelegate ConnectionMessage;
        string FormatOwnException(int lineoffset, Exception ex);
        string LineCommentString { get; }
        string SimulateParamsUse(IDbDataParameter[] cmdParams);
        List<KeyValuePair<string, int>> ParseNamedBookmarks(string script);
        void GetConnectionStringKeywordMap(Dictionary<KnownNyaqtConnectionKeys, string> knownKeywords, Dictionary<string, string> keywordMap);
    }

    public class DatabaseEntityInfo : IComparable<DatabaseEntityInfo>
    {
        string _clipboardText1;
        public string ClipboardText1
        {
            get { return _clipboardText1; }
            set { _clipboardText1 = value; }
        }

        string _clipboardText2;
        public string ClipboardText2
        {
            get { return _clipboardText2; }
            set { _clipboardText2 = value; }
        }

        string _databaseName;
        public string DatabaseName
        {
            get { return _databaseName; }
            set { _databaseName = value; }
        }

        string _tableNamespace;
        public string TableNamespace
        {
            get { return _tableNamespace; }
            set { _tableNamespace = value; }
        }

        string _tableName;
        public string TableName
        {
            get { return _tableName; }
            set { _tableName = value; }
        }

        string _columnName;
        public string ColumnName
        {
            get { return _columnName; }
            set { _columnName = value; }
        }

        string _relatedColumnName;
        public string RelatedColumnName
        {
            get { return _relatedColumnName; }
            set { _relatedColumnName = value; }
        }

        string _tableDescription;
        public string TableDescription
        {
            get { return _tableDescription; }
            set { _tableDescription = value; }
        }

        string _tableType;
        public string TableType
        {
            get { return _tableType; }
            set { _tableType = value; }
        }

        string _relatedTableNamespace;
        public string RelatedTableNamespace
        {
            get { return _relatedTableNamespace; }
            set { _relatedTableNamespace = value; }
        }

        string _relatedTable;
        public string RelatedTable
        {
            get { return _relatedTable; }
            set { _relatedTable = value; }
        }

        bool _isOutGoing;
        public bool IsOutGoing
        {
            get { return _isOutGoing; }
            set { _isOutGoing = value; }
        }

        bool isPrimaryKey;
        public bool IsPrimaryKey
        {
            get { return isPrimaryKey; }
            set { isPrimaryKey = value; }
        }

        bool isNullable;
        public bool IsNullable
        {
            get { return isNullable; }
            set { isNullable = value; }
        }

        string _displayName;
        public string DisplayName
        {
            get { return _displayName; }
            set { _displayName = value; }
        }

        public int CompareTo(DatabaseEntityInfo other)
        {
            return _displayName.CompareTo(other._displayName);
        }
    }

    public class ServerInfo
    {
        public ServerInfo()
        {
        }

        public ServerInfo(string displayName, string serverAddress)
        {
            this.DisplayName = displayName;
            this.ServerAddress = serverAddress;
        }

        string _displayName;
        public string DisplayName
        {
            get { return _displayName; }
            set { _displayName = value; }
        }

        string _serverAddress;
        public string ServerAddress
        {
            get { return _serverAddress; }
            set { _serverAddress = value; }
        }

        public override string ToString()
        {
            return _displayName;
        }
    }
}
































